#!/usr/bin/bash

# Copyright (c) 2023. Huawei Technologies Co.,Ltd.ALL rights reserved.
# This program is licensed under Mulan PSL v2.
# You can use it according to the terms and conditions of the Mulan PSL v2.
#          http://license.coscl.org.cn/MulanPSL2
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.

###################################
#@Author    :   gaoyue
#@Contact   :   2829807379@qq.com
#@Date      :   2022/8/30
#@License   :   Mulan PSL v2
#@Desc      :   Test "libsmi" command
###################################

source "${OET_PATH}"/libs/locallibs/common_lib.sh

function pre_test() {
    LOG_INFO "Start to prepare the test environment"
    DNF_INSTALL "libsmi"
    cp /usr/share/mibs/ietf/IF-MIB IF-MIB
    LOG_INFO "End to prepare the test environment"
}
function run_test() {
    LOG_INFO "Start to run test."
    smidump -f types IF-MIB 2>&1 | grep -e "# IF-MIB type derivation tree"
    CHECK_RESULT $? 0 0 "L$LINENO: -f types No Pass"
    smidump -f types --types-no-implicit IF-MIB 2>&1 | grep -e "# IF-MIB type derivation tree"
    CHECK_RESULT $? 0 0 "L$LINENO: -f types --types-no-implicit No Pass"
    smidump -f sizes IF-MIB 2>&1 | grep -E '[.*]'
    CHECK_RESULT $? 0 0 "L$LINENO: -f sizes No Pass"
    smidump -f sizes --sizes-variables IF-MIB 2>&1 | grep -E '[.*]'
    CHECK_RESULT $? 0 0 "L$LINENO: -f sizes --sizes-variables No Pass"
    smidump -f xml IF-MIB 2>&1 | grep -e "This module has been generated by smidump"
    CHECK_RESULT $? 0 0 "L$LINENO: -f xml No Pass"
    smidump -f xml --xml-no-schema IF-MIB 2>&1 | grep -e "This module has been generated by smidump"
    CHECK_RESULT $? 0 0 "L$LINENO: -f xml --xml-no-schema No Pass"
    smidump -f xml --xml-no-doctype IF-MIB 2>&1 | grep -e "This module has been generated by smidump"
    CHECK_RESULT $? 0 0 "L$LINENO: -f xml --xml-no-doctype No Pass"
    smidump -f compliances IF-MIB 2>&1 | grep -e "+mr-n"
    CHECK_RESULT $? 0 0 "L$LINENO: -f compliances No Pass"
    smidump -f boilerplate IF-MIB 2>&1 | grep -e "# IF-MIB security considerations boilerplate"
    CHECK_RESULT $? 0 0 "L$LINENO: -f boilerplate No Pass"
    LOG_INFO "End to run test."

}
function post_test() {
    LOG_INFO "Start to restore the test environment."
    DNF_REMOVE "$@"
    rm -rf ./result* ./IF_MIB* ./if-mib*
    LOG_INFO "End to restore the test environment."
}

main "$@"
